<template>
  <PiTable
    border
    isSearch
    rowKey="number"
    :tableData
    :tableColumns
    :pagination="page"
    @pageChange="pageChange"
    @radioChange="radioChange"
    @confirmSetting="confirmSetting"
  >
    <template #icon>
      <img src="@/assets/images/icon_part.png" title="部件" />
    </template>
    <template #name="{ row }">
      <el-input v-if="row.status === 'edit'" v-model.trim="row.name" placeholder="请输入" />
      <span v-else>{{ row.name }}</span>
    </template>
    <template #number="{ row }">
      <el-link type="primary" @click="toDetail(row)">{{ row.number }}</el-link>
    </template>
    <template #lifecycleState="{ row }">
      {{ row.lifecycleState.display }}
    </template>
    <template #createTime="{ row }">
      {{ row.createTime && $timeFormat(new Date(row.createTime), 'YYYY-MM-DD HH:mm:ss') }}
    </template>
    <template #handle="{ row }">
      <el-space>
        <el-link type="primary" @click="changeTableData(row)">编辑</el-link>
        <el-link type="danger">删除</el-link>
      </el-space>
    </template>
  </PiTable>
</template>

<script setup name="docDetailReferenceDoc">
const loading = ref(false);
const tableData = ref([]);
const { $timeFormat } = window.$fn;
const { documentApi } = window.$api;
const router = useRouter();
const route = useRoute();
const page = reactive({
  pageNum: 1, //当前页
  pageSize: 10, //每页数
  total: 0, //数据总量
});
const tableColumns = ref();
onMounted(() => {
  getData();
});
onMounted(() => {
  getData();
});
const getData = () => {
  loading.value = true;
  const params = {
    tableID: 'DocRefDocTable',
    oid: route.query.oid,
    page: page.pageNum,
    range: page.pageSize,
  };
  documentApi.getWTDocReferenceDocs(params).then((res) => {
    loading.value = false;
    if (res.success) {
      tableColumns.value = res.data.columns.map((item) => ({ ...item, sortable: true }));
      tableData.value = res.data.rows;
      page.total = res.data.total;
    }
  });
};
const toDetail = (row) => {
  router.push({
    name: 'documentDetail',
    query: {
      oid: row.oid,
    },
  });
};
const pageChange = (pageNum, pageSize) => {
  page.pageNum = pageNum;
  page.pageSize = pageSize;
  getData();
};
const radioChange = (val) => {
  console.log(val);
};
const confirmSetting = (columns) => {
  // page.pageNum = 1;
  //保存设置的列
  // window.$api.demo.saveColumns({ tableName: 'demo', columns, userName: '' }).then((res) => {
  //   proTable.value.getColumns();
  // });
  // getData();
  console.log(columns);
};
</script>

<style scoped lang="less"></style>
